package com.twopai.login.presenter;

import android.util.Log;

import com.twopai.framelibrary.entity.RunShopDetailEntity;
import com.twopai.framelibrary.http.BaseObjectBean;
import com.twopai.login.contact.LoginContact;
import com.twopai.login.model.LoginModel;
import com.twopai.mvpbase.BasePresenter;
import com.twopai.mvpbase.RxScheduler;

import io.reactivex.Observable;
import io.reactivex.functions.Consumer;
import okhttp3.RequestBody;

/**
 * author : twopai
 * description :
 */
public class LoginPresenter extends BasePresenter<LoginContact.View>implements LoginContact.Presenter {
    LoginContact.model model;

    public LoginPresenter() {
        this.model = new LoginModel();
    }

    @Override
    public void newsInfo(RequestBody body) {
        if(!isViewAttached())return;
        if(model==null)return;
        model.newsInfo(body)
                .compose(RxScheduler.<BaseObjectBean<RunShopDetailEntity>>Obs_io_main())
                .as(mView.<BaseObjectBean<RunShopDetailEntity>>bindAutoDispose())
                .subscribe(new Consumer<BaseObjectBean<RunShopDetailEntity>>() {
                    @Override
                    public void accept(BaseObjectBean<RunShopDetailEntity> dataBeanBaseObjectBean) throws Exception {
                        Log.e("RunShopDetailActivity","dataBeanBaseObjectBean="+dataBeanBaseObjectBean.toString());
                        mView.newsInfoSuccess(dataBeanBaseObjectBean);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.newsInfoError(throwable);
                    }
                });
    }
}
